package com.lemon.funplus.cheanh;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.util.Log;
import android.view.View;

public class EraserIndicatorView extends View {
	protected ShapeDrawable brushIndicator;

	protected int canvasHeight = -1, canvasWidth = -1;
	protected int maxRadius;
	protected int radius = 0;
	protected EraserSettingDialog frag;

	public EraserIndicatorView(Context context, EraserSettingDialog frag) {
		super(context);
		this.frag = frag;
		brushIndicator = new ShapeDrawable(new OvalShape());
		radius = frag.radius;
		Paint p = brushIndicator.getPaint();
		p.setColor(Color.BLACK);
		p.setStyle(Style.STROKE);
		this.updateRadius();
	}

	protected void onDraw(Canvas canvas) {
		if (canvasHeight < 0) {
			canvasWidth = canvas.getWidth();
			canvasHeight = canvas.getHeight();
			maxRadius = canvasWidth > canvasHeight ? canvasHeight : canvasWidth;
			this.frag.updateSlider();
		}
		radius = frag.radius;
		brushIndicator.setBounds((canvasWidth - radius) / 2, (canvasHeight - radius) / 2, (canvasWidth + radius) / 2, (canvasHeight + radius) / 2);
		brushIndicator.draw(canvas);
	}

	protected void updateRadius() {
		this.invalidate();
	}
}
